home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / bipl.zip / PROGS.ZIP / DIFFN.ICN < prev    next >
Text File  |  1992-11-26  |  2KB  |  88 lines

  1. ############################################################################
  2. #
  3. #    File:     diffn.icn
  4. #
  5. #    Subject:  Program to show differences among files
  6. #
  7. #    Author:   Robert J. Alexander
  8. #
  9. #    Date:     April 30, 1990
  10. #
  11. ###########################################################################
  12. #  
  13. #   This program shows the differences between n files. Is is invoked as
  14. #
  15. #        diffn file1 file2 ... filen
  16. #  
  17. ############################################################################
  18. #
  19. #  Links: dif
  20. #
  21. ############################################################################
  22. #
  23. #  Most of the work is done by an external procedure, dif().  This
  24. #  program analyzes the command line arguments, sets up a call to
  25. #  dif(), and displays the results.
  26. #
  27.  
  28.  
  29. link dif
  30. global f1,f2
  31. record dfile(file,linenbr)
  32.  
  33.  
  34. procedure main(arg)
  35.   local f, i, files, drec, status
  36.   #
  37.   #  Analyze command line arguments, open the files, and output
  38.   #  some initial display lines.
  39.   #
  40.   if *arg < 2 then stop("usage: diffn file file ...")
  41.   f := list(*arg)
  42.   every i := 1 to *arg do
  43.         f[i] := dfile(open(arg[i]) | stop("Can't open ",arg[i]),0)
  44.   files := list(*arg)
  45.   every i := 1 to *arg do {
  46.     write("File ",i,": ",arg[i])
  47.     files[i] := diff_proc(myread,f[i])
  48.   }
  49.   #
  50.   #  Invoke dif() and display its generated results.
  51.   #
  52.   every drec := dif(files) do {
  53.     status := "diffs"
  54.     write("==================================")
  55.     every i := 1 to *drec do {
  56.       write("---- File ",i,", ",
  57.                (drec[i].pos > f[i].linenbr & "end of file") |
  58.          "line " || drec[i].pos,
  59.          " ---- (",arg[i],")")
  60.       listrange(drec[i].diffs,drec[i].pos)
  61.     }
  62.   }
  63.   if /status then write("==== Files match ====")
  64.   return
  65. end
  66.  
  67.  
  68. #
  69. #  listrange() -- List a range of differing lines, each preceded by its
  70. #  line number.
  71. #
  72. procedure listrange(dlist,linenbr)
  73.   local x
  74.   every x := !dlist do {
  75.     write(x); linenbr +:= 1
  76.   }
  77.   return
  78. end
  79.  
  80.  
  81. #
  82. #  myread() -- Line-reading procedure to pass to dif().
  83. #
  84. procedure myread(x)
  85.   return x.linenbr <- x.linenbr + 1 & read(x.file)
  86. end
  87.  
  88.